xl: prevent attempts to remove non-attached pci pass-through devices
authorGianni Tedesco <gianni.tedesco@citrix.com>
Wed, 4 Aug 2010 13:24:43 +0000 (14:24 +0100)
committerGianni Tedesco <gianni.tedesco@citrix.com>
Wed, 4 Aug 2010 13:24:43 +0000 (14:24 +0100)
Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
tools/libxl/libxl_pci.c

index e74a3f1adeb9de7a58f0ffff4eed9f1a0ff8d858..4fc4727b8024618a5b278b41d486a9d5783fe923 100644 (file)
@@ -564,12 +564,20 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcide
 
 int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev)
 {
+    libxl_device_pci *assigned;
     char *path;
     char *state;
-    int hvm, rc;
+    int hvm, rc, num;
     int stubdomid = 0;
 
-    /* TODO: check if the device can be detached */
+    if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) {
+        if ( !is_assigned(assigned, num, pcidev->domain,
+                         pcidev->bus, pcidev->dev, pcidev->func) ) {
+            XL_LOG(ctx, XL_LOG_ERROR, "PCI device not attached to this domain");
+            return ERROR_INVAL;
+        }
+    }
+
     libxl_device_pci_remove_xenstore(ctx, domid, pcidev);
 
     hvm = is_hvm(ctx, domid);